
import UserAPI from '../api/user.js';

export const User={
   state:{
      userlist:[],
      user_total_count:0,
      userinfo:[]
   },
   mutations:{
      setUserList(state,list){
          state.userlist=list;
      },
      setUserTotalCount(state,total_count){
          state.user_total_count=total_count;
      },
      setUserInfo(state,info){
          state.userinfo=info;
      }
   },
   actions:{
      loadUserList(context,data){
          UserAPI.getUserList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setUserList',response.data.data.list);
                  context.commit('setUserTotalCount',response.data.data.total_count);
              }
          })
      },
      //获取详情
      loadUserInfo(context,data){
          UserAPI.getUserInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setUserInfo',response.data.info);
              }
          })
      }
   },
   getters:{
      getUserList:state =>{
         return state.userlist
      },
      getUserTotalCount: state =>{
         return state.user_total_count
      },
      getUserInfo:state => {
          return state.userinfo;
      }
   }
}
